package com.eedi.framework.protocol.controller.sys;

import com.eedi.framework.common.pojo.CommonResult;
import com.eedi.framework.common.pojo.PageResult;
import com.eedi.framework.common.util.object.BeanUtils;
import com.eedi.framework.protocol.controller.sys.vo.SysProtocolHistoryPageReq;
import com.eedi.framework.protocol.controller.sys.vo.SysProtocolHistoryResp;
import com.eedi.framework.protocol.dal.dataobject.ProtocolHistoryDO;
import com.eedi.framework.protocol.service.SysProtocolHistoryService;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.eedi.framework.common.pojo.CommonResult.success;


@Tag(name = "系统界面 - 协议配置历史版本")
@RestController
@RequestMapping("/protocol-history")
@Validated
public class SysProtocolHistoryController {

    @Resource
    private SysProtocolHistoryService sysProtocolHistoryService;

    @GetMapping("/get")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<SysProtocolHistoryResp> getProtocolHistory(String systemProtocolHistoryId) {
        ProtocolHistoryDO protocolHistory = sysProtocolHistoryService.getProtocolHistory(systemProtocolHistoryId);
        return success(BeanUtils.toBean(protocolHistory, SysProtocolHistoryResp.class));
    }

    @PostMapping("/page")
    public CommonResult<PageResult<SysProtocolHistoryResp>> getProtocolHistoryPage(@RequestBody @Valid SysProtocolHistoryPageReq pageReqVO) {
        PageResult<ProtocolHistoryDO> pageResult = sysProtocolHistoryService.getProtocolHistoryPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, SysProtocolHistoryResp.class));
    }


}
